import os
import logging
from .times import get_time_str
from .logging import get_logger

class Recorder:
    def __init__(self, cfg):
        self.cfg = cfg
        # the postfix of record-dir is ${task}-${model_name}
        tasks = self.cfg['TASKS']
        task_str = ''
        for task in tasks:
            if task_str != '':
                task_str = task_str + '&'
            task_str = task_str + task
        postfix = task_str + '-' + self.cfg["MODELS"]["type"]
        # create work-dir
        self.record_dir = os.path.join(self.cfg["WORKDIR"], get_time_str(postfix=postfix))
        if not os.path.exists(self.record_dir):
            os.makedirs(self.record_dir, exist_ok=True)

    def backup_cfg_file(self):
        self.cfg.backup(self.record_dir)
